import pandas as pd, json
import plotly.express as px
df = pd.read_csv("https://covid.ourworldindata.org/data/owid-covid-data.csv")
html_path = r"/home/pi/HDD/webpages/charts/OWiD{html_file}.html"
folder_path = r"/home/pi/HDD/Datasets"
final_csv_path = r"{folder_path}/Covid19_OWiD.csv".format(folder_path=folder_path)
filtered_csv_path = r"{folder_path}/Filtered_Covid19_OWiD.csv".format(folder_path=folder_path)
filtered_json_path = r"{folder_path}/Filtered_Covid19_OWiD.json".format(folder_path=folder_path)
summary_json_path = r"{folder_path}/Summary_Covid19_OWiD.json".format(folder_path=folder_path)
df.to_csv(final_csv_path,index=False)
df_filtered= df[(df["location"].isin(["Brazil","India","Mexico","Canada","United States"] ))&(df["date"]>"2020-03-15")]
df_filtered.to_csv(filtered_csv_path,index=False)
df_filtered.to_json(filtered_json_path)
total, deaths = df[(df["date"]==df["date"].max()) & (df["iso_code"] =="OWID_WRL")][["total_cases","total_deaths"]].sum()
summary = {"total":total, "deaths":deaths, "active":"", "as_on": df["date"].max()}
summary
with open(summary_json_path, "w") as summaryFile:
json.dump(summary,summaryFile)
fig = px.scatter(df[(df.iso_code=='IND')&(df.date>'2020-03-15')], x="date", y=["total_cases","total_deaths"], title='India Total Cases and Deaths').update_traces(mode='lines+markers')
fig.write_html(html_path.format(html_file = "IndiaTotalCasesAndDeaths"))
fig.show()
fig = px.scatter(df[(df.iso_code=='IND')&(df.date>'2020-03-15')], x="date", y=["new_cases","new_deaths"], title='India New Cases and Deaths').update_traces(mode='lines+markers')
fig.write_html(html_path.format(html_file = "IndiaNewCasesAndDeaths"))
fig.show()
fig = px.scatter(df[(df.continent=='Asia')&(df.date>'2020-03-15')], x="date", y=["total_cases"], title='Asia Total Cases',color='location').update_traces(mode='lines+markers')
fig.write_html(html_path.format(html_file = "AsiaTotalCases"))
fig.show()
fig = px.scatter(df[(df.continent=='North America')&(df.date>'2020-03-15')], x="date", y=["total_cases"], title='North America Total Cases',color='location').update_traces(mode='lines+markers')
fig.write_html(html_path.format(html_file = "NorthAmericaTotalCases"))
fig.show()
fig = px.scatter(df[(df.continent=='South America')&(df.date>'2020-03-15')], x="date", y=["total_cases"], title='South America Total Cases',color='location').update_traces(mode='lines+markers')
fig.write_html(html_path.format(html_file = "SouthAmericaTotalCases"))
fig.show()
fig = px.scatter(df[(df.continent=='Europe')&(df.date>'2020-03-15')], x="date", y=["total_cases"], title='Europe Total Cases',color='location').update_traces(mode='lines+markers')
fig.write_html(html_path.format(html_file = "EuropeTotalCases"))
fig.show()
fig = px.scatter(df[(df.continent=='Oceania')&(df.date>'2020-03-15')], x="date", y=["total_cases"], title='Oceania Total Cases',color='location').update_traces(mode='lines+markers')
fig.write_html(html_path.format(html_file = "OceaniaTotalCases"))
fig.show()
fig = px.scatter(df[(df.location.isin(['India','Canada','United States','Mexico','Brazil']))&(df.date>'2020-03-25')], x="date", y=["total_cases"], title='Total Cases Comparison Log scale',color='location',log_y=True).update_traces(mode='lines+markers')
fig.write_html(html_path.format(html_file = "TotalCasesComparisonLogScale"))
fig.show()
fig = px.scatter(df[(df.location.isin(['India','Canada','United States','Mexico','Brazil']))&(df.date>'2020-03-25')], x="date", y=["total_deaths"], title='Total Deaths Comparison Log scale',color='location',log_y=True).update_traces(mode='lines+markers')
fig.write_html(html_path.format(html_file = "TotalDeathsComparisonLogScale"))
fig.show()